#include "ProxyLogicPlugin.h"
#include "ProxyLogicModule.h"
#include "Protocol/Protocol.h"

bool FragrantGrass::ProxyLogicModule::Init()
{
    return true;
}

bool FragrantGrass::ProxyLogicModule::Shut()
{
    return true;
}

bool FragrantGrass::ProxyLogicModule::Execute()
{


    return true;
}


bool FragrantGrass::ProxyLogicModule::AfterInit()
{
	m_pNetModule = m_pPluginManager->FindModule<INetModule>();
	m_pNetClientModule = m_pPluginManager->FindModule<INetClientModule>();


	m_pNetModule->register_net_message_handler(Protocol::EGEC_REQ_LAG_TEST, this, &ProxyLogicModule::OnLagTestProcess);

    return true;
}

void FragrantGrass::ProxyLogicModule::OnLagTestProcess(const SOCK nSockIndex, const int nMsgID, const char * msg, const uint32_t nLen)
{
	std::string msgDatag(msg, nLen);
	m_pNetModule->send_msg_with_out_head(Protocol::EGameMsgID::EGEC_ACK_GATE_LAG_TEST, msgDatag, nSockIndex);

	//TODO improve performance
	//NetObject* pNetObject = m_pNetModule->GetNet()->GetNetObject(nSockIndex);
	//if (pNetObject)
	//{
	//	const int gameID = pNetObject->GetGameID();
	//	m_pNetClientModule->SendByServerIDWithOutHead(gameID, nMsgID, msgDatag);
	//}
}
